<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ attribute name="page" type="java.lang.Integer" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Integer" required="true"%>
<%@ attribute name="total" type="java.lang.Integer" required="true"%>
<%@ attribute name="url" type="java.lang.String" required="true"%>

<c:set var="pageTotal">${total == 0 ? 0.0 : total % pageSize > 0 ? (total - total%pageSize) / pageSize + 1 : total / pageSize}</c:set>
<c:set var="pageTotal" value="${fn:substring(pageTotal,0,fn:indexOf(pageTotal,'.'))}"/>
<c:set var="begin" value="${page - 3 > 0 ? page - 3 : 1}"/>
<c:set var="end" value="${pageTotal - page > 3 ? page + 3 : pageTotal}"/>
 <c:forEach var="x" begin="1" end="${3-(page-begin)}">
    <c:if test="${end<pageTotal}"><c:set var="end" value="${end+1}"/></c:if>
</c:forEach>
<c:forEach var="x" begin="1" end="${(3-(end-page)) < 0 ? 0 : 3-(end-page) }">
    <c:if test="${begin>1}"><c:set var="begin" value="${begin-1}"/></c:if>
</c:forEach>
<div class="pagination">
  <ul>
	<c:if test="${page > 1}"><li><a href="${url}${page > 1 ? page-1 : 1}">Prev</a></li></c:if>
	<c:if test="${page > 4 && pageTotal > 7}"><li><a href="${url}1">1</a></li><li><span>...</span></li></c:if>
	<c:forEach var="n" begin="${begin}" end="${end}">
		<c:if test="${n != page}"><li><a href="${url}${n}">${n}</a></li></c:if>
		<c:if test="${n == page}"><li class="active"><a href="javascript:void(0);">${n}</a></li></c:if>
	</c:forEach>
	<c:if test="${page < pageTotal - 3 && pageTotal > 7}"><li><span>...</span></li><li><a href="${url}${pageTotal}">${pageTotal}</a></li></c:if>
<c:if test="${page < pageTotal}"><li><a class="next" href="${url}${page < pageTotal ? page+1 : pageTotal}">Next</a></li></c:if>
 </ul>
</div>







